package cn.tedu.vue_master.config;

import cn.tedu.vue_master.interceptor.BasicAuthInterceptor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Slf4j
@Configuration
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class BasicAuthConfiguration implements WebMvcConfigurer {

    private final BasicAuthInterceptor basicAuthInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] permitUrls = {
                "/doc.html",
                "/favicon.ico",
                "/**/*.js",
                "/**/*.css",
                "/swagger-resources",
                "/v2/api-docs",
                "/users/login",
                "/testController/print",
                "/oauth/**"
        };
        InterceptorRegistration registration = registry.addInterceptor(basicAuthInterceptor);
        registration.addPathPatterns("/testController/**")
                .excludePathPatterns(permitUrls);
    }
}
